"""正确率分析服务"""
from app.ai.evaluation_engine import get_evaluation_engine
from app.ai.recommendation_service import get_recommendation_service
from typing import Dict, Any, List


class AnalysisService:
    """正确率分析服务类"""
    
    def __init__(self):
        self.evaluation_engine = get_evaluation_engine()
        self.recommendation_service = get_recommendation_service()
    
    async def analyze_error_attribution(
        self,
        user_id: str,
        question_ids: List[str]
    ) -> Dict[str, Any]:
        """错误归因分析"""
        # 模拟错误分析
        return {
            "user_id": user_id,
            "analysis_date": "2024-01-15T10:00:00Z",
            "error_distribution": {
                "knowledge": {"count": 45, "percentage": 50.0, "examples": []},
                "thinking": {"count": 25, "percentage": 27.8, "examples": []},
                "technique": {"count": 15, "percentage": 16.7, "examples": []},
                "attention": {"count": 5, "percentage": 5.5, "examples": []}
            },
            "recommendations": [
                "加强法律基础理论学习",
                "多进行案例分析训练",
                "学习答题技巧"
            ]
        }
    
    async def predict_accuracy(
        self,
        user_id: str,
        days_ahead: int = 30
    ) -> Dict[str, Any]:
        """预测正确率"""
        historical_data = [
            {"date": "2024-01-01", "accuracy": 65},
            {"date": "2024-01-08", "accuracy": 68},
            {"date": "2024-01-15", "accuracy": 72}
        ]
        return await self.evaluation_engine.predict_accuracy(
            user_id, historical_data, days_ahead
        )
    
    async def get_recommendations(
        self,
        user_id: str,
        error_type: str = None
    ) -> Dict[str, Any]:
        """获取提升方案推荐"""
        weak_areas = ["contract_law", "criminal_procedure"]
        materials = await self.recommendation_service.recommend_study_materials(
            user_id, weak_areas, count=5
        )
        return {
            "user_id": user_id,
            "recommendations": materials
        }


analysis_service = AnalysisService()

